package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.services.core.PoiItem;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.dialog.adapter.NearInformationAdapter;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.cy.dialog.BaseDialog;

import java.util.List;

public class NearInformationDialog extends BaseDialog {
    private RecyclerView rv_location;
    private NearInformationAdapter nearInformationAdapter;

    public NearInformationDialog(Context context) {
        super(context);
    }

    public NearInformationDialog(Context context, int themeResId) {
        super(context, themeResId);


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dialog_near_information);
        canceledOnTouchOutside(true);
        animType(AnimInType.BOTTOM);

        rv_location = findViewById(R.id.rv_location);
        nearInformationAdapter = new NearInformationAdapter();
        nearInformationAdapter.setAddItemOnClickListener(new AddItemOnClickListener() {
            @Override
            public void onSkipClicked(int position, Object mObject) {
                if(null != addItemOnClickListener){
                    addItemOnClickListener.onSkipClicked(position,mObject);
                }
            }
        });
        rv_location.setLayoutManager(new LinearLayoutManager(getContext()));
        rv_location.setAdapter(nearInformationAdapter);


        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        ViewGroup.LayoutParams params =  rv_location.getLayoutParams();
        params.height = (int) (dm.heightPixels / 2) ;
        rv_location.setLayoutParams(params);
    }


    /**
     * 添加数据
     * @param poiItemList
     */
    public void setADD(List<PoiItem> poiItemList){
        if(null != nearInformationAdapter){
            nearInformationAdapter.setAdd(poiItemList);
        }
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener){
        this.addItemOnClickListener = addItemOnClickListener;
    }


    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
